package com.boy.rpc.framework.console;

import com.boy.rpc.framework.console.appenum.RefreshModeEnum;
import com.boy.rpc.framework.console.appenum.ShowTypeEnum;
import com.boy.rpc.framework.console.bean.RKey;
import com.boy.rpc.framework.console.utils.ztree.ZNode;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 常量类
 */
public class Constant {

    public static final int REDIS_CONNECTION_TIMEOUT = 1000;
    public static final int REDIS_MAX_IDLE = 200;
    public static final long REDIS_MAX_WAIT = 30000;

    /** redis properties key **/
    public static final String REDIS_PROPERTIES_SERVER_NUM_KEY	= "redis_server_num";
    public static final String REDIS_PROPERTIES_HOST_PREFIX_KEY	= "redis_host_";
    public static final String REDIS_PROPERTIES_NAME_PREFIX_KEY	= "redis_name_";
    public static final String REDIS_PROPERTIES_PORT_PREFIX_KEY	= "redis_port_";
    public static final String REDIS_PROPERTIES_PASSWORD_PREFIX_KEY	= "redis_password_";
    public static final String REDIS_PROPERTIES_KEYS_PRXFIX_KEY = "redis_keys";

    /** zk properties key **/
    public static final String ZK_PROPERTIES_SERVER_NUM_KEY = "zk.sum";
    public static final String ZK_PROPERTIES_HOST_PREFIX_KEY = "zk.host_";
    public static final String ZK_PROPERTIES_NAME_PREFIX_KEY = "zk.name_";
    public static final String ZK_PROPERTIES_PORT_PREFIX_KEY = "zk.port_";
    public static final String ZK_PROPERTIES_NODE_PRXFIX_KEY = "zk.keys";

    public static final int ZK_SESSION_TIMEOUT = 5000;
    public static final int ZK_CONNECTION_TIMEOUT = 1000;

    /**默认查询所有**/
    public static String REDIS_PROPERTIES_KEYS_DEFAULT_VALUE = "*";

    public static String BASE_PATH = "/boy-rpc-console";

    /**redisTemplatesMap RedisTemplate信息**/
    public static final Map<String, RedisTemplate> redisTemplatesMap = new HashMap<String, RedisTemplate>();

    /**redisServerCache 缓存信息**/
    public static final CopyOnWriteArrayList<Map<String, Object>> redisServerCache = new CopyOnWriteArrayList<Map<String, Object>>();

    /**redis-keys 集合**/
    public static final Map<String, CopyOnWriteArrayList<RKey>> redisKeysListMap = new HashMap<String, CopyOnWriteArrayList<RKey>>();

    /**默认redis大小**/
    public static final int REDIS_DEFAULT_DB_SIZE = 15;
    public static final int DEFAULT_DBINDEX = 0;
    /**默认分页大小**/
    public static final int DEFAULT_ITEMS_PER_PAGE = 10;

    /**连接字符串**/
    public static final String DEFAULT_SEPARATOR = "_";
    public static final String DEFAULT_REDISKEY_SEPARATOR = ":";

    /** query key **/
    public static final String MIDDLE_KEY = "middle";
    public static final String HEAD_KEY = "head";
    public static final String TAIL_KEY = "tail";
    public static final String EMPTY_STRING = "";



    /**ztree 列表数据**/
    public static final CopyOnWriteArrayList<ZNode> redisNavigateZtree = new CopyOnWriteArrayList<ZNode>();


    public static volatile RefreshModeEnum refreshMode = RefreshModeEnum.manually;
    public static volatile ShowTypeEnum showType = ShowTypeEnum.show;

    /** operator for log **/
    public static final String GET_KV = "GET_KV";


    /**
     * redis连接索引
     */
    public static ThreadLocal<Integer> redisConnectionDbIndex = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };
}